package cn.zhaozhiqi.controller.app;

import cn.zhaozhiqi.pojo.domain.Order;
import cn.zhaozhiqi.pojo.dto.app.CreateOrderDto;
import cn.zhaozhiqi.pojo.dto.app.DriverLocationDto;
import cn.zhaozhiqi.pojo.dto.app.OtherFreeDto;
import cn.zhaozhiqi.pojo.query.PageQueryWrapper;
import cn.zhaozhiqi.result.JSONResult;
import cn.zhaozhiqi.result.PageResult;
import cn.zhaozhiqi.service.IOrderService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/app/order")
public class AppOrderController {

    @Autowired
    public IOrderService orderService;

    @Operation( summary= "乘客接收详细支付单信息",description = "乘客接收详细支付单信息接口")
    @Parameter(name = "orderNo",description = "订单编号",required = true)
    @PostMapping("/detail/customer/{orderNo}")
    public JSONResult SendCustomerDetail(@PathVariable("orderNo")String orderNo){
        return JSONResult.success(orderService.SendCustomerDetail(orderNo));
    }


    @Operation( summary= "司机端确认所有费用发送给乘客，创建统一支付单",description = "司机端确认所有费用发送给乘客，创建统一支付单接口")
    @Parameter(name = "orderNo",description = "订单编号",required = true)
    @PostMapping("/payorder/send/{orderNo}")
    public JSONResult SendPayorder(@PathVariable("orderNo")String orderNo){
        return JSONResult.success(orderService.SendPayorder(orderNo));
    }

    @Operation( summary= "司机端回显订单所有费用",description = "司机端回显订单所有费用接口")
    @Parameter(name = "orderNo",description = "订单编号",required = true)
    @GetMapping("/driver/orderbill/{orderNo}")
    public JSONResult driverGetBill(@PathVariable("orderNo")String orderNo){
        return JSONResult.success(orderService.driverGetBill(orderNo));
    }

    @Operation( summary= "司机端确认其他费用",description = "司机端确认其他费用接口")
    @Parameter(name = "OtherFreeDto",description = "确认的其他费用",required = true)
    @PostMapping("/confirm")
    public JSONResult confirmOtherFree(@RequestBody @Valid OtherFreeDto dto){
        return JSONResult.success(orderService.confirmOtherFree(dto));
    }


    @Operation( summary= "司机结束代驾",description = "司机结束代驾接口")
    @PostMapping("/end/driving")
    public JSONResult endDriving(){
        return JSONResult.success(orderService.endDriving());
    }

    @Operation( summary= "司机开始代驾",description = "司机开始代驾接口")
    @PostMapping("/start/driving")
    public JSONResult startDriving(){
        return JSONResult.success(orderService.startDriving());
    }

    @Operation( summary= "司机到达代驾点",description = "司机到达代驾点接口")
    @PostMapping("/arrive")
    public JSONResult driverArrive(){
        return JSONResult.success(orderService.driverArrive());
    }

    @Operation( summary= "乘客端定时拉取redis中的司机实时位置",description = "乘客端定时拉取redis中的司机实时位置接口")
    @GetMapping("/pull/driver/location")
    public JSONResult pullDriverLocation(){
        return JSONResult.success(orderService.pullDriverLocation());
    }

    @Operation( summary= "司机端实时存储位置到redis",description = "司机端实时存储位置到redis接口")
    @Parameter(name = "orderNo",description = "传过来的订单编号",required = true)
    @PostMapping("/setDriverGEOInRedis")
    public JSONResult setDriverGEOInRedis(@RequestBody @Valid DriverLocationDto dto){
        return JSONResult.success(orderService.setDriverGEOInRedis(dto));
    }


    @Operation( summary= "乘客订单状态查询",description = "乘客订单状态查询接口")
    @PostMapping("/current/customer")
    public JSONResult getCustomerOrder(){
        return JSONResult.success(orderService.getCustomerOrder());
    }


    @Operation( summary= "司机订单状态查询",description = "司机订单状态查询接口")
    @PostMapping("/currentOrder")
    public JSONResult currentOrder(){
        return JSONResult.success(orderService.currentOrder());
    }

    @Operation( summary= "司机秒杀接单",description = "司机秒杀接单接口")
    @Parameter(name = "orderNo",description = "传过来的订单编号",required = true)
    @PostMapping("/orderkill/{orderNo}")
    public JSONResult killOrder(@PathVariable("orderNo") String orderNo){
        return JSONResult.success(orderService.killOrder(orderNo));
    }

    @Operation( summary= "保存Order",description = "基础对象保存接口")
    @Parameter(name = "order",description = "保存的对象",required = true)
    @PostMapping("/create")
    public JSONResult saveOrder(@RequestBody @Valid CreateOrderDto dto){
        return JSONResult.success(orderService.saveOrder(dto));
    }

    @Operation( summary= "超时自动取消Order",description = "超时自动取消Order接口")
    @Parameter(name = "orderNo",description = "传过来的订单编号",required = true)
    @PostMapping("/cancel/auto/{orderNo}")
    public JSONResult autoCancelOrder(@PathVariable("orderNo") String orderNo){
        return JSONResult.success(orderService.autoCancelOrder(orderNo));
    }


}
